﻿using System;
using CzfSDK;
using MySql.Data.MySqlClient;

namespace Server
{
	public static class LogManager
	{
		/// <summary>
		/// 增加道具记录
		/// </summary>
		public static void AddItemLog(int userid, int itemid, int count, int afterCount, string msg1, string msg2)
		{
			ItemLogDB (userid, itemid, count, afterCount, msg1, msg2, 1);
		}

		#region DB
		/// <summary>
		/// Items the log D.
		/// </summary>
		/// <param name="userid">Userid.</param>
		/// <param name="itemid">Itemid.</param>
		/// <param name="count">Count.</param>
		/// <param name="msg1">Msg1.</param>
		/// <param name="msg2">Msg2.</param>
		/// <param name="category">1-增加 0-减少</param>
		private static void ItemLogDB(int userid, int itemid, int count, int afterCount, string msg1, string msg2, int category)
		{
			var sql = "insert into itemlog(userid, itemid, count, category, aftercount, msg1, msg2, createtime)"+
				" values(@userid, @itemid, @count, @category, @aftercount, @msg1, @msg2, now())";
			MysqlPool.current.ExecuteNonQuery (sql, 
				new MySqlParameter ("@userid", userid),
				new MySqlParameter ("@itemid", itemid),
				new MySqlParameter ("@count", count),
				new MySqlParameter ("@afterCount", afterCount),
				new MySqlParameter ("@msg1", msg1),
				new MySqlParameter ("@msg2", msg2),
				new MySqlParameter ("@category", category)
			);
		}

		// 战斗结束日志
		public static void FightLog(int userId, int time, int type)
		{
			var sql = "insert into fightlog(userid, time, createtime, type) values(@userid, @time, @createtime, @type)";
			MysqlPool.current.ExecuteNonQuery (sql, 
				new MySqlParameter ("@userid", userId),
				new MySqlParameter ("@time", time),
				new MySqlParameter ("@createtime", DateTime.Now),
				new MySqlParameter ("@type", type)
			);
		}
		#endregion
	}
}

